/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package prison.dataaccess;

import java.sql.*;
import java.util.Vector;
import prison.data.*;
import java.util.Calendar;

/**
 *
 * @author joli
 */
public class UserDAO {

    private static UserDAO instance = null;

    private UserDAO() {
    }

    public static UserDAO getInstance() {
        if (instance == null) {
            instance = new UserDAO();
            return instance;
        } else {
            return instance;
        }
    }

    public User getUsers(String userId, String password) throws SQLException {
        User c = null;
        String sql = "SELECT * FROM users WHERE nickname=? AND password=?";

        Connection conn = MySqlDatabase.getInstance().getConnection();
        PreparedStatement ps = conn.prepareStatement(sql);

        //invoeren van parameters
       ps.setString(1, userId);
        ps.setString(2,password);
        //uitvoeren
        ResultSet res = ps.executeQuery();

        while (res.next()) {
            int gebruikerId = res.getInt(1);
            String nickname = res.getString(2);
            String wachtwoord = res.getString(3);
            String naam = res.getString(4);
            String voornaam = res.getString(5);
            //Calendar geboortedatum = res.getDate(6);
            int level = res.getInt(7);
            int rasId = res.getInt(8);
            int laatsteLocatie = res.getInt(9);

            c = new User(gebruikerId,nickname,wachtwoord,naam,voornaam,level,rasId,laatsteLocatie);
            
        }
        conn.close();

        return c;
    }

  /*  public void saveUser(User b) throws SQLException {

        String sql = "INSERT INTO Users (UserID, Naam, Aankoopprijs, ISBN, Auteur, Uitgeverij) VALUES (?,?,?,?,?,?)";
        Connection conn = MySqlDatabase.getInstance().getConnection();
        PreparedStatement ps = conn.prepareStatement(sql);

        ps.setInt(1, b.getRegistratienummer());
        ps.setString(2, b.getNaam());
        ps.setDouble(3, b.getAankoopprijs());
        ps.setString(4, b.getIsbn());
        ps.setString(5, b.getAuteur());
        ps.setString(6, b.getUitgeverij());

        ps.executeUpdate();
        conn.close();
    }

    public void saveUsers(Vector<User> Users) throws SQLException {
        for (User b : Users) {
            saveUser(b);
        }
    }*/

    
    /* public void deleteUser (User b) throws SQLException {
    String sql = "DELETE FROM Users WHERE UserID=?";
    Connection conn = MySqlDatabase.getInstance().getConnection();
    PreparedStatement ps = conn.prepareStatement(sql);
    ps.setInt(1,b.getRegistratienummer());
    ps.executeUpdate();
    conn.close();
    }*/
}
